package be.nepherte.movmanager.client.ui.tabframework;

import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.ImageResource;
import com.google.gwt.user.client.ui.Composite;

/**
 * This class represents a tab in the graphical user interface. Each tab has:
 * <ul>
 * 		<li>a name</li>
 * 		<li>a description</li>
 * 		<li>a color</li>
 * </ul>
 * This information is encapsulated in a {@link TabInfo} object. The name is 
 * used as a visual link label for the tab. The description serves as a 
 * explanation of each tab and will be shown as well. A tab is a single panel 
 * of the TabSink. They are meant to be lazily instantiated (by creating an 
 * instance only when necessary) so that the application doesn't pay for all 
 * of them on startup.
 * 
 * <p>
 * Copyright © 2010 Bart Verhoeven
 * </p>
 * 
 * <p>
 * This file is part of MovManager.
 * </p>
 * 
 * <p>
 * MovManager is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 3 of the License, or (at your option) any later
 * version.
 * </p>
 * 
 * <p>
 * MovManager is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * </p>
 * 
 * <p>
 * You should have received a copy of the GNU General Public License along with
 * MovManager. If not, see http://www.gnu.org/licenses/.
 * </p>
 * 
 * @author	Bart Verhoeven
 * @version	0.1
 */
public abstract class Tab extends Composite {
	
	/**
     * Constructor for this tab. It has no effect whatsoever.
     */
	protected Tab() {};
	
	/**
	 * Specifies what happens upon showing this page: nothing.
	 */
	public abstract void onShow();
	
	/**
	 * Specifies what happens upon hiding this page: nothing.
	 */
	public abstract void onHide();
	
	/**
     * An image provider to make images available to tabs.
     */
	public interface Images extends ClientBundle {
		@Source("logo.png")
		ImageResource logo();
	}
	
	/**
	 * Encapsulated information about a tab. Holds information about the name,
	 * color, description of the tab and the tab itself. Each tab is expected to
	 * have a static <tt>init()</tt> method that will be called by the
	 * {@link TabSink} on startup.
	 */
	public abstract static class TabInfo {
		/**An instance of this tab.*/
		private Tab instance;
		/**The name of this tab.*/
		private String name;
		/**The description of this tab.*/
		private String description;
		/**The color of this tab in hexadecimal representation.*/
		private String color;
		
		/**
		 * Creates a TabInfo object. The name is used as a link label on the tab.
		 * The description will be shown when the tab is active, against a
		 * <tt>color</tt> background.
		 * 
		 * @param	name
		 *          name of the tab.
		 * @param	description
		 *          description of the tab
		 * @param	color
		 *          the background color of the tab
		 */
		protected TabInfo(String name, String description, String color) {
			this.name = name;
			this.description = description;
			this.color = color;
		}
		
		/**
         * Returns an instance of InfoTab.
         * 
         * @return	a new InfoTab
         */
		public abstract Tab createInstance();
		
		/**
		 * Retrieves an instance of the tab associated with this TabInfo. If
		 * there already was an instance created, it will return the already
		 * created instance. Else, a new instance is created.
		 * 
		 * @return	an instance of this tab. a new one if none have been created,
		 *         	else an existing one.
		 */
		public Tab getInstance() {
			if (instance != null)
				return instance;
			
			return (instance = createInstance());
		}
		
		/**
         * Retrieves the name of this tab.
         * 
         * @return	name
         */
		public String getName() {
			return name;
		}
		
		/**
         * Retrieves the description of this tab.
         * 
         * @return	description
         */
		public String getDescription() {
			return description;
		}
		
		/**
         * Retrieves the color of this tab.
         * 
         * @return	color
         */

		public String getColor() {
			return color;
		}
	}
}
